package com.pan.cuiniubi.driver;

import com.pan.cuiniubi.create.CreateEntity;
import com.pan.cuiniubi.entity.Table;
import com.pan.cuiniubi.utils.ReadYamlTool;
import com.pan.cuiniubi.utils.WriterTool;
import com.pan.cuiniubi.enumn.LaminaEnum;

import java.util.List;

public class EntityDriver {

    public void outputEntity(Table table){
        CreateEntity createEntity = new CreateEntity();
        Boolean lombok = (Boolean) ReadYamlTool.getInstance().getMapLaminaValue(LaminaEnum.entity,"lombok");
        String entityString = createEntity.getEntityString(table,lombok);

        String myRootPath = System.getProperty("user.dir");
        String entityPath = myRootPath + "\\output\\entity\\"+table.getTableName()+".java";

        WriterTool.output(entityPath,entityString);

    }

    @Deprecated
    public void outputEntity2(Table table){
        CreateEntity createEntity = new CreateEntity();
        String entityString = createEntity.getEntityString(table,true);
        String myRootPath = System.getProperty("user.dir");
        String entityPath2 = myRootPath + "\\src\\main\\java\\com\\pan\\entity\\"+table.getTableName()+".java";
        WriterTool.output(entityPath2,entityString);

    }

    public void outputEntity(List<Table> tables){
        tables.stream().forEach(this::outputEntity);
    }

}
